<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<style>
.asbutton {
	display: block;
	width:100px; background:#ccc; padding: 3px;
}
.adsearch {
	float: right; width: 300px;
	padding: 20px 10px; background: #fff; border: 1px solid #ccc;
	margin-bottom: 10px;
}
</style>
<div class="middle myclear">
	<div class="pad10">
		
		<h3><?php echo $lang['title']; ?></h3>
		<table class="martop10 marbottom10" width="100%">
			<tr>
				<td class="ver-middle" style="text-align:left">
					<?php
					$msg = trim($this->input->get('msg',true));
					if($msg != ''){
					?>
					<p class="msg"><?php echo $msg;?></p>
					<br />
					<?php }?>
				</td>
				<td class="ver-middle" style="text-align:right">
					<input type="button" onclick="window.location.href='<?php echo site_url('category/create')?>'" value="<?php echo $lang['nCreate']; ?>" />
				</td>
			</tr>
		</table>
		<h3>
			<?php echo $lang['list']; ?>
		</h3>
		<table width="100%" border="1" class="martop10 tbl-list">
			<tr>
				<td class="pad5 text-center td-label" width="20">
					#
				</td>
				<td class="pad5 text-center td-label"  width="40">
					<b><?php echo $lang['listorder']; ?></b>
				</td>
				<td class="pad5 td-label">
					<b><?php echo $lang['name']; ?></b>
				</td>
				
				
								
				<td class="pad5 td-label text-center" width="80">
					<b><?php echo $lang['cdate']; ?></b>
				</td>
				
				<td class="pad5 td-label text-center" width="40" >
					<b><?php echo $lang['status']; ?></b>
				</td>
				
				<td class="pad5 text-center td-label" width="100" >
					<b><?php echo $lang['action']; ?></b>
				</td>
                
                
			</tr>
			
			<?php
			foreach($lstCategory as $category)
			{
			?>
				<tr class="row">
					<td class="pad5 text-center" >
						<?php echo $category['catid']; ?>
					</td>
					<td class="pad5 text-center">
						<?php echo $category['listorder']; ?>
					</td>
					<td class="pad5">
						<a href="<?php echo site_url('category/edit/'.$category['catid'])?>">
							<?php echo $category['catname']; ?>
						</a>
					</td>
				
					<td class="pad5 text-center">
						<?php echo mdate("%d-%m-%Y", $category['installtime']); ?>
					</td>
					<td class="pad5 text-center">
						<?php if(($category['status']==0)){ ?>
							<a href="<?php echo site_url('category/active/'.$category['catid'].'/'.$category['status'])?>" onclick="return _active(1);">
								<img src="<?php echo site_url();?>images/start.png" title="Mở" alt="" height="16" width="16">
							</a>
						<?php }else{ ?>
							<a href="<?php echo site_url('category/active/'.$category['catid'].'/'.$category['status'])?>" onclick="return _active(2);">
								<img src="<?php echo site_url();?>images/stop.png" title="Đóng" alt="" height="16" width="16">
							</a>
						<?php } ?>
                    	
					</td>
					<td class="pad5 text-center">
						<a href="<?php echo site_url('category/edit/'.$category['catid'])?>">
							<img src="<?php echo site_url();?>images/edit.png" title="Chỉnh sửa" alt="" height="16" width="16">
						</a>
						&nbsp;
						<a href="<?php echo site_url('category/delete/'.$category['catid'])?>" onclick="return _delete();">
							<img src="<?php echo site_url();?>images/delete.png" title="Xóa" alt="" height="16" width="16">
						</a>
						&nbsp;
						<img src="<?php echo site_url();?>images/remkdir.png" title="Đổi tên thư mục" alt="" height="16" width="16">&nbsp;
						<img src="<?php echo site_url();?>images/set.png" title="Cài đặt" alt="" height="16" width="16">
					</td>
                    
				</tr>
			<?php
			}
			?>
			
		</table>
		<?php
		if($numCurrItem > 0)
		{
		?>
			<table width="100%" class="martop10">
				<tr>
					<td class="pad5">
						Show <?php echo $cPage; ?> / <?php echo $pCount; ?> pages
					</td>
					
					<td class="pad5 text-right ppage">
						<?php
						if($cPage > 1)
						{
							?>
							<a href="<?php echo site_url('category/view')."?cpage=" . ($cPage - 1); ?>">Previous</a>
							<?php
						}
						
						foreach($lstPaging as $page)
						{
							if($page > 0)
							{
						?>
							<a <?php echo ($page == $cPage) ? 'class="curr"' : '';?> href="<?php echo site_url('category/view')."?cpage=$page"; ?>"><?php echo $page;?></a>
						<?php
							}
						}
						
						if($cPage < $pCount)
						{
							?>
							<a href="<?php echo site_url('category/view')."?cpage=" . ($cPage + 1); ?>">Next</a>
							<?php
						}
						?>
					</td>
				</tr>
			</table>
		<?php
		}
		?>
	</div>
</div>
<input type="hidden" id="assign"/>
<script type="text/javascript">
	function _delete() {
		return confirm('Chắc chắn muốn xoá? Hành động này sẽ không thể khôi phục!');
	}
	function _active(id) {
		if(id==1)
			return confirm('<?php echo $lang['category_status_0']; ?>');
		else
			return confirm('<?php echo $lang['category_status_1']; ?>');
	}
	$(function(){
		$('.tbl-list .row').mouseover(function(){
			$(this).css('background','#ffc');
		});
		$('.tbl-list .row').mouseout(function(){
			$(this).css('background','none');
		});
	});
	function categorysFilterChange()
	{
		var type = $('#slcType').val();
		var level = $('#slcLevel').val();
		var group = $('#slcGroup').val();
		var keyword = $('#txtKeyword').val();
		var cmofsale = $('input[name="cmofsale"]').val();
		
		window.location = '<?php echo site_url('category/view/'); ?>?type=' + type + '&level=' + level + '&keyword=' + keyword;
	}
    function assign_campaign()
    {
        var value = $('#empty-array-form').find('select').val();
        var lstCampaign = value;
        var catid = $('#assign').val();
        //alert(lstCampaign);
        var strURL="<?php echo site_url('category/assign?catid=');?>"+catid+"&lst="+lstCampaign;
        var success = function(data)
        {
            alert(data);
            domain_tooltip_preview_remove();
        };
        getAjax(strURL,"",'', '', '', false, success);
    }
	function ajax_tooltip2(val,e)
    {    
        var strURL="<?php echo site_url('category/get_list_campaign?catid=');?>"+val;
        $('#assign').val(val);
        var strId= '#tooltip2';
        var strId2='#content2';
        tooltip_preview (e,strId);
        var success = function(data)
        {
            $(strId2).html(data);
            tooltip_preview (e,strId);
        };
        getAjax(strURL,"",'', '', '', false, success);
    }
    function getLstid()
    {
        var total="";
        var x=document.getElementsByName("lstidCheckbox");
        for(var i=0; i < x.length; i++)
        {
            if(x[i].checked)
            {
                total +=x[i].value + ",";
            }
        }
        var t=total.replace(/,$/,"");
        $('#lstid').val(t);
    }
    function domain_tooltip_preview_remove()
    {
        tooltip_preview_remove('.ttip-ad-preview');
        $('#content2').html('<div style="width: 300px;height:246px;text-align: center;"><img src="/images/ajax-loader.gif" style="margin-top: 80px;"/></div>');
    }
	function categoryAction(url, id)
	{
		var action = $('#slcAction_'+id).val();
		var onSuccess = function(data)
		{
			var objData = jQuery.parseJSON(data);
			if(objData.code == 1)
			{
				alert('Update thành công');
				window.location.reload(true);
			}
			else
			{
				alert('Update lỗi');
			}
		};
		getAjax(url, 'action=' + action + '&id=' + id, '', '', '', false, onSuccess);
	}
	function adSearch()
	{
		$('.adsearch').animate({
		    opacity: 1,
		    height: 'toggle'
		 });
		//$('.asbutton').toggleClass('asbutton2');
	}
</script>